package com.pearadmin.pro.modules.project.rest;

import com.pearadmin.pro.modules.project.domain.Project;
import com.pearadmin.pro.common.aop.annotation.Log;
import com.pearadmin.pro.common.constant.ControllerConstant;
import com.pearadmin.pro.common.web.base.BaseController;
import com.pearadmin.pro.common.web.domain.Result;
import  com.pearadmin.pro.modules.project.domain.Project;
import com.pearadmin.pro.modules.project.dto.ProjectDTO;
import  com.pearadmin.pro.modules.project.param.ProjectRequest;
import  com.pearadmin.pro.modules.project.service.ProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 项目信息Controller
 *
 * @author ChenJian
 * @date 2021-08-29
 */
@Api(tags = {"项目信息"})
@RestController
@RequestMapping(ControllerConstant.ADMIN+"project/project")
public class ProjectController extends BaseController
{
    @Resource
    private ProjectService projectService;

    /**
     * 查询项目信息列表
     *  @param projectRequest 查询参数
     *  @return {@link Result}
     */
    @GetMapping("/page")
    @Log(title = "项目信息列表")
    @ApiOperation(value = "项目信息列表")
    public Result<Project> list(ProjectRequest projectRequest)
    {
        return success(projectService.page(projectRequest));
    }


    /**
     * 新增保存项目信息
     * @param project 查询参数
     * @return {@link Result}
     */
    @PostMapping("/save")
    @Log(title = "新增项目信息")
    @ApiOperation(value = "新增项目信息")
    public Result save(@RequestBody ProjectDTO project)
    {
        return auto(projectService.saveOrUpdate(project));
    }

    /**
     * 查询项目信息详情
     *
     * @param id 项目信息ID
     * @return 项目信息
     */
    @GetMapping("/selectById")
    @Log(title = "查询项目信息详情")
    @ApiOperation(value = "查询项目信息详情")
    public Result<ProjectDTO> selectById(@RequestParam Long id)
    {
        return success(projectService.selectProjectById(id));
    }



    /**
     * 修改保存项目信息
     * @param project 查询参数
     * @return {@link Result}
     */
    @PutMapping("/update")
    @Log(title = "修改项目信息")
    @ApiOperation(value = "修改项目信息")
    public Result update(@RequestBody ProjectDTO project)
    {
        return auto(projectService.saveOrUpdate(project));
    }


    /**
     * 删除保存项目信息
     * @param id 查询参数
     * @return {@link Result}
     */
    @DeleteMapping("/remove")
    @Log(title = "删除项目信息")
    @ApiOperation(value = "删除项目信息")
    public Result remove(@RequestParam Long id)
    {
        return auto(projectService.removeById(id));
    }

    /**
    * 批量删除项目信息
    * @param ids 批量删除
    * @return {@link Result}
    */
    @DeleteMapping("removeBatch")
    @Log(title = "批量删除项目信息")
    @ApiOperation(value = "批量删除项目信息")
    public Result removeBatch(@RequestParam List<Long> ids){
        return auto(projectService.removeByIds(ids));
    }

}
